﻿using System;
using System.Windows.Forms;

namespace PhiStore.Security
{
    internal partial class CredentialsUI : Form
    {
        public CredentialsUI()
        {
            InitializeComponent();
            this.Text = "Add Credentials";
        }

        public CredentialsUI(PhiCredentials cred) : this()
        {
            Username.Text = cred.Username;
            ServerCredentials.Checked = cred.IsServerCredential;
            this.Text = "Change Credentials";
        }

        public PhiCredentials Credentials
        {
            get
            {
                if (ServerCredentials.Checked)
                {
                    return new ServerCredentialContainer(Username.Text, Password.Text);
                }
                else
                {
                    return new ClientCredentials(Username.Text, Password.Text);
                }
            }
        }

        private void Save_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
        }
    }
}
